package com.bsoft.hospitalchs.ui.childinfo;

import android.content.Context;
import android.util.Log;

import com.bsoft.hospitalchs.api.SimpleMyCallBack;
import com.bsoft.hospitalchs.base.BaseCommonPresenter;
import com.bsoft.hospitalchs.model.ChildRecordList;
import com.bsoft.hospitalchs.model.HttpExceptionBean;
import com.bsoft.hospitalchs.model.RecordInfo;
import com.bsoft.hospitalchs.utils.ToastUtils;
import com.google.gson.Gson;

/**
 * Created by 泅渡者
 * Created on 2017/5/18.
 */

public class ChildinfoPresenter extends BaseCommonPresenter<ChildinfoContract.View> implements ChildinfoContract.Presenter {
    public ChildinfoPresenter(ChildinfoContract.View view, Context context) {
        super(view, context);
    }

    @Override
    public void getDate(RecordInfo recordInfo) {
        Gson gson = new Gson();
        String str = gson.toJson(recordInfo);
        Log.e("req",str);
        mCompositeSubscription.add(apiImple.getChildList(recordInfo)
                .subscribe(newMySubscriber(new SimpleMyCallBack<ChildRecordList>() {
                    @Override
                    public void onError(HttpExceptionBean mHttpExceptionBean) {
                        super.onError(mHttpExceptionBean);
                        ToastUtils.showShort(mHttpExceptionBean.toString());
                    }

                    @Override
                    public void onNext(ChildRecordList bean) {
                        Log.e("res",bean.toString());
                        if (bean.getCode() == 200) {
                            view.showCaseList(bean);
                        }else if (bean.getCode() == 403){

                        }else {
                            ToastUtils.showShort("服务器响应异常！");
                        }
                        view.stopRefresh();
                    }
                })));
    }
}
